'use strict';


import Base from './base.js';

const querystring = require('querystring');
var ttutil = require("../../business/ttutil");
var http = require('http');
const getToken = require('../../business/getwebtoken.js');
const getUserInfo = require('../../business/getwebuserinfo.js');
var Url = require("url");
var SqlPool = require('../../business/sql_pool.js');
export default class extends Base {

    
    async indexAction() {
        var codeurl=this.param("codeurl");
        var money=this.param("money");
        var paytype=this.param("paytype");
        var paytypename="";
        if(paytype==1)
        {
            paytype="alipay";
            paytypename="支付宝";
        }
        else
        {
            paytype="wx";
            paytypename="微信";
        }
        this.assign("codeurl",codeurl);
        this.assign("money",money);
        this.assign("paytype",paytype);
        this.assign("paytypename",paytypename);
        this.display("");
    }
    async callbackAction() {

        var arg = Url.parse(this.http.req.url, true).query;
        //console.log("arg======"+ this.http.req.url);
        var app_key="6b3af6bf-3016b7b8-a03d3b66-9b072ba6";
        var self = this;
        var postData = "";
        var out_order_id =arg.out_order_id;
        var price = arg.price;
        var type = arg.type;
        var paytime=arg.paytime;
        var extend=arg.extend;
        var sign=arg.sign;

        var mysign=ttutil.md5(ttutil.md5(out_order_id + price + type + paytime + extend)+app_key);
        if (sign==mysign) {
            SqlPool.x_query('CALL ps_mark_pay_to_payed(?,?,?);', [out_order_id, "", ""], function (err, rows, fields) {
                if (err) {
                    return;
                }
            });
        }
        this.http.res.end("success");
        return;
    }
}